"use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

if (!Object.values) {
    Object.values = Object.values ? Object.values : function (obj) {
        var allowedTypes = ["[object String]", "[object Object]", "[object Array]", "[object Function]"];
        var objType = Object.prototype.toString.call(obj);

        if (obj === null || typeof obj === "undefined") {
            throw new TypeError("Cannot convert undefined or null to object");
        } else if (!~allowedTypes.indexOf(objType)) {
            return [];
        } else {
            // if ES6 is supported
            if (Object.keys) {
                return Object.keys(obj).map(function (key) {
                    return obj[key];
                });
            }

            var result = [];
            for (var prop in obj) {
                if (obj.hasOwnProperty(prop)) {
                    result.push(obj[prop]);
                }
            }

            return result;
        }
    };
}

if (!Array.prototype.includes) {
    Object.defineProperty(Array.prototype, 'includes', {
        value: function value(searchElement, fromIndex) {

            if (this == null) {
                throw new TypeError('"this" is null or not defined');
            }

            // 1. Let O be ? ToObject(this value).
            var o = Object(this);

            // 2. Let len be ? ToLength(? Get(O, "length")).
            var len = o.length >>> 0;

            // 3. If len is 0, return false.
            if (len === 0) {
                return false;
            }

            // 4. Let n be ? ToInteger(fromIndex).
            //    (If fromIndex is undefined, this step produces the value 0.)
            var n = fromIndex | 0;

            // 5. If n ≥ 0, then
            //  a. Let k be n.
            // 6. Else n < 0,
            //  a. Let k be len + n.
            //  b. If k < 0, let k be 0.
            var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);

            function sameValueZero(x, y) {
                return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y);
            }

            // 7. Repeat, while k < len
            while (k < len) {
                // a. Let elementK be the result of ? Get(O, ! ToString(k)).
                // b. If SameValueZero(searchElement, elementK) is true, return true.
                if (sameValueZero(o[k], searchElement)) {
                    return true;
                }
                // c. Increase k by 1.
                k++;
            }

            // 8. Return false
            return false;
        }
    });
}

if (!Object.entries) {
    Object.entries = function (obj) {
        var ownProps = Object.keys(obj),
            i = ownProps.length,
            resArray = new Array(i); // preallocate the Array
        while (i--) {
            resArray[i] = [ownProps[i], obj[ownProps[i]]];
        }return resArray;
    };
}

if (!String.prototype.padStart) {
    String.prototype.padStart = function padStart(targetLength, padString) {
        targetLength = targetLength >> 0; //floor if number or convert non-number to 0;
        padString = String(typeof padString !== 'undefined' ? padString : ' ');
        if (this.length > targetLength) {
            return String(this);
        } else {
            targetLength = targetLength - this.length;
            if (targetLength > padString.length) {
                padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed
            }
            return padString.slice(0, targetLength) + String(this);
        }
    };
}

if (!String.prototype.padEnd) {
    String.prototype.padEnd = function padEnd(targetLength, padString) {
        targetLength = targetLength >> 0; //floor if number or convert non-number to 0;
        padString = String(typeof padString !== 'undefined' ? padString : ' ');
        if (this.length > targetLength) {
            return String(this);
        } else {
            targetLength = targetLength - this.length;
            if (targetLength > padString.length) {
                padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed
            }
            return String(this) + padString.slice(0, targetLength);
        }
    };
}

if (!String.prototype.includes) {
    String.prototype.includes = function (search, start) {
        'use strict';

        if (typeof start !== 'number') {
            start = 0;
        }

        if (start + search.length > this.length) {
            return false;
        } else {
            return this.indexOf(search, start) !== -1;
        }
    };
}

if (typeof Promise !== 'function') {
    throw new TypeError('A global Promise is required');
}

if (typeof Promise.prototype["finally"] !== 'function') {
    var speciesConstructor = function speciesConstructor(O, defaultConstructor) {
        if (!O || (typeof O === "undefined" ? "undefined" : _typeof(O)) !== 'object' && typeof O !== 'function') {
            throw new TypeError('Assertion failed: Type(O) is not Object');
        }
        var C = O.constructor;
        if (typeof C === 'undefined') {
            return defaultConstructor;
        }
        if (!C || (typeof C === "undefined" ? "undefined" : _typeof(C)) !== 'object' && typeof C !== 'function') {
            throw new TypeError('O.constructor is not an Object');
        }
        var S = typeof Symbol === 'function' && _typeof(Symbol.species) === 'symbol' ? C[Symbol.species] : undefined;
        if (S == null) {
            return defaultConstructor;
        }
        if (typeof S === 'function' && S.prototype) {
            return S;
        }
        throw new TypeError('no constructor found');
    };

    var shim = {
        "finally": function _finally(onFinally) {
            var promise = this;
            if ((typeof promise === "undefined" ? "undefined" : _typeof(promise)) !== 'object' || promise === null) {
                throw new TypeError('"this" value is not an Object');
            }
            var C = speciesConstructor(promise, Promise); // throws if SpeciesConstructor throws
            if (typeof onFinally !== 'function') {
                return Promise.prototype.then.call(promise, onFinally, onFinally);
            }
            return Promise.prototype.then.call(promise, function (x) {
                return new C(function (resolve) {
                    return resolve(onFinally());
                }).then(function () {
                    return x;
                });
            }, function (e) {
                return new C(function (resolve) {
                    return resolve(onFinally());
                }).then(function () {
                    throw e;
                });
            });
        }
    };
    Object.defineProperty(Promise.prototype, 'finally', { configurable: true, writable: true, value: shim["finally"] });
}